package android.framework.reflaction.injectors;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;


public class ReflactionHelper {
	
	public static <T extends Annotation> List<Field> getAllFieldWithSpecificAnnotatetion(Class<?> cls, Class<T> annotation){
		List<Field> result = new ArrayList<Field>(); 
		Field[] fields = cls.getDeclaredFields();
		for (Field field : fields) {
			if(field.getAnnotation(annotation) != null){
				result.add(field);
			}
		}
		return result;
	}
	
	public static List<Field> getAllFields(Class<?> cls){
		List<Field> result = new ArrayList<Field>();
		
		if(cls != Object.class){
			for (Field field : getAllFields(cls.getSuperclass())) {
				result.add(field);
			}
			for (Field field : cls.getDeclaredFields()) {
				result.add(field);
			}
		}
		
		return result;
	}
}
